<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>积分详情</title>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/font-awesome.min93e3.css"/>
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/style.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet">
<style type="text/css">
body{font-size: 14px;padding: 10px;}
.dataTables_info {font-size: 12px}
.dataTables_paginate {font-size: 12px;}
.dataTables_wrapper,table.dataTable{clear: none;}
</style>
</head>
<body>
	<div class="container-fluid">
		<div class="row">
			<div class="col-sm-12">
				<div class="tabs-container">
                    <div class="tabs-left">
                        <ul class="nav nav-tabs">
                            <li class="active"><a data-toggle="tab" href="#tab-8">基础信息</a></li>
                            <li class=""><a data-toggle="tab" href="#tab-9">积分记录</a></li>
                        </ul>
                        <div class="tab-content ">
                            <div id="tab-8" class="tab-pane active">
                                <div class="panel-body">
									<table style="width: 100%;border-collapse: separate;border-spacing: 0px 10px;">
										<tr>
											<td style="width: 70px;">会员昵称：</td>
											<td style="width: 30%;"><span id="name"></span></td>
											<td style="width:70px;">会员手机：</td>
											<td><span id="phone"></span></td>
										</tr>
										<tr>
											<td>会员等级：</td>
											<td><span id="crm_member_level"></span></td>
											<td>积分状态：</td>
											<td><span id="integralType"></span></td>
										</tr>
										<tr>
											<td>剩余积分：</td>
											<td><span id="crm_score"></span></td>
											<td>使用积分：</td>
											<td><span id="useIntegral"></span></td>
										</tr>
										<tr>
											<td>过期积分：</td>
											<td><span id="expiredIntegral"></span></td>
											<td></td>
											<td></td>
										</tr>
									</table>
                                </div>
                            </div>
                            <div id="tab-9" class="tab-pane">
                                <div class="panel-body">
                                	<table id="myTable" class="display">
										<thead>
											<tr>
												<th>积分变更</th>
												<th>途径</th>
								                <th>来源</th>
								                <th>时间</th>
											</tr>
										</thead>
									</table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
			</div>
		</div>
	</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.16/js/jquery.dataTables.min.js"></script>
<script type="text/javascript">
var path = "<%=path%>";
var memberId = getUrlParam("memberId");
var myDataTable;
var dataTable_index = 1;

$(function(){
	init();
});

function init(){
	$.post(path+"/member/ajaxGetMember",{id:memberId},function(data){
		if(data.status == "200"){
			var member = data.data;
			
			$("#name").text(member.name);
			$("#phone").text(member.phone);
			$("#crm_member_level").text(member.crm_member_level);
			var integralType = "";
			if(member.integral_type == 1){
				integralType = "正常";
			}else if(member.integral_type == 2){
				integralType = "冻结";
			}
			$("#integralType").text(integralType);
			$("#crm_score").text(member.crm_score);
			$("#useIntegral").text(member.use_integral);
			$("#expiredIntegral").text(member.expired_integral);
		}else if(data.status == "201"){
			alert("无记录");
		}else{
			alert("远程请求出错");
		}
	},"json");
	
	myDataTable = dataTable();
}

function func_dataTableReload(resetPaging) {
	if(resetPaging != undefined){
	    myDataTable.ajax.reload(null,resetPaging);
	}else{
		myDataTable.ajax.reload();
		dataTable_index = 1;
	}
}

function func_AjaxUrl() {
    return path + "/scan/integral/getPage";
}

function func_columns() {
    var jsonArr = [
        {"data": "integral"},
        {"data": "gain_way"},
        {"data": "store_name"},
        {"data": "create_time"}
    ];
    return jsonArr;
}

function func_ajaxData() {
    var jsonObject = new Object();
    jsonObject.memberId = memberId;
    return jsonObject;
}

function dataTable() {
    return $('#myTable').DataTable({
        processing: true,
        ordering: false,
        searching: false,
        info: true,
        autoWidth: false,
        lengthChange: false,
        language: {
            emptyTable: '没有数据表',
            info: '从第 _START_ 到第 _END_ 条数据；总共有 _TOTAL_ 条记录',
            infoEmpty: '没有数据',
            lengthMenu: '每页显示 _MENU_ 条记录',
            loadingRecords: '正在加载数据....',
            processing: '正在处理数据....',
            zeroRecords: '没有找到匹配的记录',
            paginate: {
                first: '首页',
                previous: '前页',
                next: '后页',
                last: '尾页'
            }
        },
        order: [[1, 'desc']],
        pageLength: 10,
        pagingType: 'full_numbers',
        columnDefs: [{
            render: function (data, type, full) {
                var result = "";
            	if(data == 1){
            		result = "手动增加";
            	}else if(data == 2){
            		result = "订单增加";
            	}else if(data == 3){
            		result = "手动减少";
            	}
                return result;
            },
            targets: 1
        },{
            render: function (data, type, full) {
                var result = "";
            	var d = new Date(data);
            	result = d.format("yyyy-MM-dd hh:mm");
                return result;
            },
            targets: 3
        }],
        columns: func_columns(),
        serverSide: true,
        ajax: {
            contentType: 'text/plain;charset=utf-8',
            type: 'POST',
            url: func_AjaxUrl(),
            data: function (d) {
                d.extra_search = func_ajaxData();
                return JSON.stringify(d);
            }
        }
	});
}

function getUrlParam(key){
	var reg = new RegExp("(^|&)"+ key +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return  unescape(r[2]); return null;
}

Date.prototype.format = function(fmt) { 
    var o = { 
       "M+" : this.getMonth()+1,                 //月份 
       "d+" : this.getDate(),                    //日 
       "h+" : this.getHours(),                   //小时 
       "m+" : this.getMinutes(),                 //分 
       "s+" : this.getSeconds(),                 //秒 
       "q+" : Math.floor((this.getMonth()+3)/3),
       "S"  : this.getMilliseconds()             //毫秒 
   }; 
   if(/(y+)/.test(fmt)) {
           fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
   }
    for(var k in o) {
       if(new RegExp("("+ k +")").test(fmt)){
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
        }
    }
   return fmt; 
}
</script>
</html>